/*[[ Name := MACDknife Author := Copyright © 2005, Robert Cochran/Automatic Forex Link := http://autoforex.biz Lots := 1.00 Notes := Use H4 timeframe. Modifications ------------- DATE MOD # DESCRIPTION ---------- -------- ------------------------------------------------------------ 15 Apr 2005 1 Autofx: Original version 19 Apr 2005 2 Autofx: Cosmetic changes -- this version is known as "old school". Update on every tick := Yes Enable Alerts := Yes Disable alert once hit := No Lots := 1 Stop Loss := 50 Take Profit := 300 Trailing Stop := 0 ]]*/ // ==================================================================================================== // DECLARATION AND ASSIGNMENT // ==================================================================================================== defines: LiveTrading(0),AccountIsMini(0); defines: Slippage(3),Risk(3),mm(1),maxTradesPerPair(1); vars: MarginCutoff(0),lotMM(0),sl(0),tp(0),getOut(0),target(0),cnt(0),CurrentTrades(0); getOut = StopLoss * Point; target = TakeProfit * Point; // ==================================================================================================== // DATE CHOKE - For testing purposes // ==================================================================================================== if Year < 2001 then Exit; // ==================================================================================================== // WAIT TEN SECONDS BETWEEN ALL TRADING ACTIONS // ==================================================================================================== if CurTime - LastTradeTime < 10 Then Exit; // ==================================================================================================== // PYRAMIDING - LINEAR // Money management risk exposure compounding // ==================================================================================================== if AccountIsMini == 0 then MarginCutoff = 1000; if AccountIsMini == 1 then MarginCutoff = 100; if FreeMargin < Margincutoff then Exit; if mm <> 0 then { lotMM = Ceil(Balance * risk / 10000) / 10; if lotMM < 0.1 then lotMM = Lots; if lotMM > 1.0 then lotMM = Ceil(lotMM); // Enforce lot size boundaries if LiveTrading == 1 then { if AccountIsMini == 1 then lotMM = lotMM * 10; if AccountIsMini == 0 and lotMM < 1.0 then lotMM = 1.0; } if lotMM > 100 then lotMM = 100; } else { lotMM = Lots; // Change mm to 0 if you want the Lots parameter to be in effect }; // ==================================================================================================== // OPEN ORDER CHECK - // Each instance of a script is attached to one currency pair. // When this check executes, it sets CurrentTrades to 1 so that // only one trade for this symbol will be open, which is enforced // by "if CurrentTrades = 0". // ==================================================================================================== CurrentTrades = 0; for cnt = 1 to TotalTrades { if OrderValue(cnt,VAL_SYMBOL) = Symbol then { CurrentTrades += 1; }; }; // ==================================================================================================== // ORDER CLOSURE // ==================================================================================================== for cnt = 1 to TotalTrades { if CurrentTrades <> 0 and OrderValue(cnt,VAL_SYMBOL) = Symbol then { if OrderValue(cnt,VAL_TYPE) = OP_BUY then { if iSTO(5,5,3,MODE_EMA,MODE_SIGNAL,0) >= 67 then { Comment("LONG at ", OrderValue(cnt,VAL_OPENPRICE), "\nClosed at: ", Bid); CloseOrder(OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS), Bid, Slippage, Violet); Exit; } }; // end OP_BUY check if OrderValue(cnt,VAL_TYPE) = OP_SELL then { if iSTO(5,5,3,MODE_EMA,MODE_SIGNAL,0) <= 33 then { Comment("SHORT at ", OrderValue(cnt,VAL_OPENPRICE), "\nClosed at: ", Ask); CloseOrder(OrderValue(cnt,VAL_TICKET), OrderValue(cnt,VAL_LOTS), Ask, Slippage, Violet); Exit; } }; // end OP_SELL check }; // end Symbol check }; // end for cnt=1 to TotalTrades // ==================================================================================================== // TRADE ENTRY // ==================================================================================================== if CurrentTrades < maxTradesPerPair then { //LONG TRADES ENTRY CRITERIA if iSTO(5,5,3,MODE_EMA,MODE_SIGNAL,0) < 63 and iMACD(36,78,9,MODE_SIGNAL,0) > iMACD(46,88,9,MODE_SIGNAL,0) then { sl = Ask - getOut; tp = Ask + target; SetOrder(OP_BUY, lotMM, Ask, Slippage, sl, tp, LIME); Comment("LONG at ", Ask, "\nStop: ", sl, "\nLimit: ", tp); Exit; }; //SHORT TRADES ENTRY CRITERIA if iSTO(5,5,3,MODE_EMA,MODE_SIGNAL,0) > 37 and iMACD(36,78,9,MODE_SIGNAL,0) < iMACD(46,88,9,MODE_SIGNAL,0) then { sl = Bid + getOut; tp = Bid - target; SetOrder(OP_SELL, lotMM, Bid, Slippage, sl, tp, RED); Comment("SHORT at ", Bid, "\nStop: ", sl, "\nLimit: ", tp); Exit; }; }; // end of if CurrentTrades < maxTradesPerPair